﻿using Neoit.Utils.Extensions;

namespace Infrastructure.Extension
{
    public static class CommonExtension
    {
        #region bool?转为bool
        /// <summary>
        /// 转为bool
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public static bool ToBool(this bool? para)
        {
            if (para == null)
            {
                return false;
            }

            return Convert.ToBoolean(para);
        }
        #endregion

        #region int?是否有值
        /// <summary>
        /// 是否有值
        /// </summary>
        /// <param name="intVal"></param>
        /// <returns></returns>
        public static bool Has(this int? intVal)
        {
            return intVal != null;
        }
        #endregion

        public static void StringTrim<T>(this T t) where T : new()
        {
            t.ForeachString(s => s.Has() ? s.Trim() : s);
        }
    }
}
